import logging

from flask import Flask, Response

from web.config.flask_app import create_flask_app
from web.config.logger_config import create_logger
from web.config.template_filters import do_list_reverse, do_to_json

from gevent import pywsgi

logger: logging.Logger = create_logger()
app: Flask = create_flask_app()
app.add_template_filter(do_list_reverse, "list_reverse")
app.add_template_filter(do_to_json, "to_json")


# @app.after_request
# def handle_after_request(response: Response):
#     print(response.data)
#     return response


if __name__ == "__main__":
    if app.debug:
        app.run(host="0.0.0.0", port=5000, debug=True)
    else:
        logger.info("http://127.0.0.1:5000")
        server = pywsgi.WSGIServer(("0.0.0.0", 5000), app)
        server.serve_forever()
